<!--空白弹出页面参考模版-->
{extend name='public/layer_base' /}
{block name='content'}
<!-- 这里写内容即可 -->
<div class="row" >
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <!-- 表单头部 -->
                <div class="box-header with-border" style="    text-align: center;">
                    <div class="btn-group">
                        <span class="btn flat btn-sm btn-default BackButton" style="pointer-events: none;">
                            <i class="fa fa-asterisk"></i>
                            请谨慎操作企业认证通过！
                        </span>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" action="" method="post"
                      enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="box-body">

                        <div class="form-group">
                            <label for="member_id" class="col-sm-2 control-label">申请人融云ID</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="member_id" name="member_id" value="{$memberinfo.member_id|default=''}" readonly
                                       type="text" class="form-control field-text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="me_uid" class="col-sm-2 control-label">申请人UID / 昵称</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="me_uid" name="me_uid" value="{$memberinfo.me_uid|default=''}（{$memberinfo.me_nick_name|default=''}）" readonly
                                       type="text" class="form-control field-text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="enterprise_name" class="col-sm-2 control-label">企业名称</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="enterprise_name" name="me_nick_name" value="{$info.enterprise_name|default=''}" readonly
                                       type="text" class="form-control field-text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="enterprise_name" class="col-sm-2 control-label">企业联系电话</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="enterprise_phone" name="enterprise_phone" value="{$info.phone|default=''}" readonly
                                       type="text" class="form-control field-text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="enterprise_province" class="col-sm-2 control-label">企业地址</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="enterprise_province" name="enterprise_province" value="{$info.enterprise_province|default=''}{$info.enterprise_city|default=''}{$info.enterprise_area|default=''}{$info.enterprise_address|default=''}" readonly
                                       type="text" class="form-control field-text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="refuse_content" class="col-sm-2 control-label">通过认证备注</label>
                            <div class="col-sm-10 col-md-4">
                                 <textarea id="refuse_content" name="refuse_content" type="text/plain" style="height: 110px;
    width: 550px;">{$data.refuse_content|raw|default=''}</textarea>
                            </div>
                        </div>

                        <input type="hidden" value="{$data}" id="id" name="id">
                    </div>
                    <!-- 表单底部 -->
                    <div class="box-footer">

                        <div class="col-sm-2">
                        </div>
                        <div class="col-sm-10 col-md-4">

                            <div class="btn-group">
                                <a class="btn btn-success btn-sm ktAjaxButton" data-toggle="tooltip" title=""
                                   data-confirm-title="是否确认通过此用户申请的企业认证" data-confirm-content="通过企业认证？"
                                   data-id="checked"
                                   data-url="{:url('actionpassenterprise')}">
                                    通过认证
                                </a>
                            </div>
                            <div class="btn-group">
                                <button type="reset" class="btn flat btn-default dataFormReset" style="padding: 5px 10px;
    font-size: 12px;
    line-height: 1.5;">
                                    重置
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    //弹框内确认  禁用回车键
    $(document).on('keydown keypress', function(event) {
        if (event.keyCode == 13) {
            event.preventDefault();
        }
    });


    $('body').on('click', '.ktAjaxButton', function (event) {
        console.log("ktAjax")
        event.preventDefault();

        if (adminDebug) {
            console.log('AjaxButton clicked.');
        }
        //是否弹出提示
        let layerConfirm = $(this).data("confirm") || 1;
        //访问方式，1为直接访问，2为layer窗口显示
        let layerType = parseInt($(this).data("type") || 1);
        //访问的url
        let url = $(this).data("url");
        //访问方式，默认post
        let layerMethod = $(this).data("method") || 'post';
        //访问成功后跳转的页面，不设置此参数默认根据后台返回的url跳转
        let go = $(this).data("go") || 'url://reload';
        // let go = 'url://close-refresh';

        //当为窗口显示时可定义宽度和高度
        let layerWith = $(this).data("width") || '80%';
        let layerHeight = $(this).data("height") || '60%';

        //窗口的标题
        let layerTitle = $(this).data('title');

        //当前操作数据的ID
        let dataId = $(this).data("id");

        let dataData;

        //如果没有定义ID去查询data-data属性
        if (dataId === undefined) {
            dataData = $(this).data("data") || {};
        } else {
            dataData = {
                "id": $("#id").val(),
                "refuse_content": $("#refuse_content").val(),
            };
        }

        if (typeof (dataData) != 'object') {
            dataData = JSON.parse(dataData);
        }

        /*需要确认操作*/
        if (parseInt(layerConfirm) === 1) {
            //提示窗口的标题
            let confirmTitle = $(this).data("confirmTitle") || '操作确认';
            //提示窗口的内容
            let confirmContent = $(this).data("confirmContent") || '您确定要执行此操作吗?';
            layer.confirm(confirmContent, {title: confirmTitle, closeBtn: 1, icon: 3}, function () {
                //如果为直接访问
                if (layerType === 1) {
                    ajaxRequests(url, layerMethod, dataData, go);
                } else if (layerType === 2) {
                    //如果为打开窗口
                    //先进行权限查询
                    if (checkAuth(url)) {
                        layer.open({
                            type: 1,
                            area: [layerWith, layerHeight],
                            title: layerTitle,
                            closeBtn: 1,
                            shift: 0,
                            content: url + "?request_type=layer_open&" + parseParam(dataData),
                            scrollbar: false,
                        });
                    }
                }
            });
        } else {
            //不需要操作确认
            if (layerType === 1) {
                //直接请求
                ajaxRequests(url, layerMethod, dataData, go);
            } else if (layerType === 2) {
                //弹出窗口
                //检查权限
                if (checkAuth(url)) {
                    //用窗口打开
                    layer.open({
                        type: 2,
                        area: [layerWith, layerHeight],
                        title: layerTitle,
                        closeBtn: 1,
                        shift: 0,
                        content: url + "?request_type=layer_open&" + parseParam(dataData),
                        scrollbar: false,
                    });
                }
            }
        }
    });

    function ajaxRequests(url, method, data, go) {
        let loadT = layer.msg('正在请求,请稍候…', {icon: 16, time: 0, shade: [0.3, '#000'], scrollbar: false,});
        $.ajax({
                url: url,
                dataType: 'json',
                type: method,
                data: data,
                success: function (result) {
                    // debugger
                    layer.close(loadT);
                    layer.msg(result.msg, {
                        icon: result.code ? 1 : 2,
                        scrollbar: false,
                    });

                    if (adminDebug) {
                        console.log('request success!');
                        if (result.code === 1) {
                            console.log('%cresult success', ';color:#00a65a');
                            go = 'url://close-refresh';
                        } else {
                            console.log('%cresult fail', ';color:#f39c12');
                            go = 'url://reload';
                        }
                        setTimeout(function () {
                            goUrl(go);
                        }, 2000);
                    }
                    // setTimeout("alert('123')", 3000 )

                },
                error: function (xhr, type, errorThrown) {
                    console.log("error")
                    //异常处理；
                    if (adminDebug) {
                        console.log('%crequest fail!', ';color:#dd4b39');
                        console.log();
                        console.log("type:" + type + ",readyState:" + xhr.readyState + ",status:" + xhr.status);
                        console.log("url:" + url);
                        console.log("data:");
                        console.log(data);
                        layer.close(loadT);
                    }
                    layer.msg('访问错误,代码' + xhr.status, {icon: 2, scrollbar: false,});
                }
            }
        );
    }
</script>
{/block}